{include file="pub/header"}
<title>添加角色</title>
</head>
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-role-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="role_name" name="role_name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="describe" cols="" rows="" class="textarea"  placeholder="描述。。。"></textarea>
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">访问权限：</label>
			<div class="formControls col-xs-8 col-sm-9">
				{foreach $menuList as $key=>$val}
					<dl class="permission-list">
						<dt>
							<label>
								<input type="checkbox" value="" name="{$key}">{$val['name']}
							</label>
						</dt>
						<dd>
							{foreach $val['children'] as $childkey=>$childval}
							<dl class="cl permission-list2 permission-list">
								<dt>
									<label class="">
										<input type="checkbox" value="" name="{$childkey}">{$childval['name']}
									</label>
								</dt>
								<dd>
									{foreach $childval['children'] as $nodekey=>$nodeval}
										<label class="">
											<input type="checkbox" value="{$val['id']},{$childval['id']},{$nodeval['id']}" name="node_id[]">{$nodeval['name']}
										</label>
									{/foreach}
								</dd>
							</dl>
							{/foreach}
						</dd>
					</dl>
				{/foreach}
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

{include file="pub/footer" /}

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">
$(function(){

    $(".permission-list dt input:checkbox").click(function(){
        $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
    });
    $(".permission-list2 dd input:checkbox").click(function(){
        var l =$(this).parent().parent().find("input:checked").length;
        var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
        if($(this).prop("checked")){
            $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
            $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
        }
        else{
            if(l==0){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
            }
            if(l2==0){
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
            }
        }
    });

	$("#form-role-add").validate({
		rules:{
			role_name:{
				required:true,
                remote:"{:url('Role/checkRoleName')}"
            },
			'role_id[]':{
			    required:true,
				minlength:1
			}
		},
		messages:{
		  	role_name:{
		  	    required: '角色名称不能为空',
                remote:'角色名称已存在'
            },
			'role_id[]':{
		  	    required:'访问目录不能为空',
				minlength:'必须选择一项目录'
			}
		},
		onkeyup:false,
		focusCleanup:false,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit(function(res){
			    if(1 == res.code){
                    var index = parent.layer.getFrameIndex(window.name);
                    layer.msg(res.msg, {icon:6, time:1000});
                    setTimeout(function(){
                        parent.location.reload();
                        parent.layer.close(index);
                    }, 1000);
                }else{
			        layer.msg(res.msg, {icon: 5,time:1000});
                }
			});

		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>